package p17.p1725;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int num = o1.getSum() - o2.getSum();
                int num2 = num == 0 ? o1.getChinese() - o2.getChinese() : num;
                int num3 = num2 == 0 ? o1.getEnglish() - o2.getEnglish() : num2;
                int num4 = num3 == 0 ? o1.getMath() - o2.getMath() : num3;
                int num5 = num4 == 0 ? o1.getName().compareTo(o2.getName()) : num4;
                return num5;
            }
        });
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生的信息:\t");
            String name = scanner.nextLine();
            System.out.println("语文:");
            String chinese = scanner.nextLine();
            System.out.println("英语:");
            String english = scanner.nextLine();
            System.out.println("数学:");
            String math = scanner.nextLine();
            //ts.add(new Student(name, Integer.parseInt(english),Integer.parseInt(math), Integer.parseInt(chinese)));
            Student s = new Student();
            s.setName(name);
            s.setChinese(Integer.parseInt(chinese));
            s.setEnglish(Integer.parseInt(english));
            s.setMath(Integer.parseInt(math));
            ts.add(s);
        }
        for (Student s : ts
                ) {
            System.out.println("s.getName() = " + s.getName());
            System.out.println("s.getChinese() = " + s.getChinese());
            System.out.println("s.getEnglish() = " + s.getEnglish());
            System.out.println("s.getMath() = " + s.getMath());
        }
    }
}
